﻿using System;
using fastCSharp;

namespace diantou.web.ajax.admin
{
    /// <summary>
    /// 考试题目调用
    /// </summary>
    [fastCSharp.code.cSharp.ajax(IsPool = true)]
    class examProblem : permissionHandle<examProblem>
    {
        /// <summary>
        /// 添加考试题目
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        public void Append(diantou.examDataAccess.examProblem value, Action<fastCSharp.net.returnValue<int>> onReturn)
        {
            if ((currentUser.Permission & dataModel.user.permission.ExamEditor) != 0)
            {
                value.UserId = currentUser.Id;
                diantou.examDataAccess.tcpCall.examProblem.append(value, onReturn);
            }
            else onReturn(0);
        }
        /// <summary>
        /// 修改考试题目
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        public void Rework(diantou.examDataAccess.examProblem value, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if ((currentUser.Permission & dataModel.user.permission.ExamEditor) != 0) diantou.examDataAccess.tcpCall.examProblem.rework(value, currentUser.Id, onReturn);
            else onReturn(false);
        }
        /// <summary>
        /// 修改考试题目显示状态
        /// </summary>
        /// <param name="value"></param>
        /// <param name="onReturn"></param>
        public void SetShowType(int id, diantou.dataModel.problemBase.showType type, Action<fastCSharp.net.returnValue<bool>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.examDataAccess.tcpCall.examProblem.setShowType(id, type, onReturn);
            else onReturn(false);
        }
        /// <summary>
        /// 获取OJ题目信息
        /// </summary>
        /// <param name="problemId"></param>
        /// <returns></returns>
        [fastCSharp.code.cSharp.ajax(IsOnlyPost = false)]
        public diantou.dataModel.problem GetProblem(int problemId)
        {
            if ((currentUser.Permission & dataModel.user.permission.ExamEditor) != 0)
            {
                fastCSharp.net.returnValue<int> examProblemId = diantou.examDataAccess.tcpCall.examProblem.getExamProblemId(problemId, currentUser.Id);
                if (examProblemId.Type == fastCSharp.net.returnValue.type.Success && examProblemId.Value >= 0)
                {
                    if (examProblemId.Value == 0) return dataAccess.clientCache.Problem[problemId];
                    return dataAccess.problem.NullProblem;
                }
            }
            return null;
        }
        /// <summary>
        /// 批量修改自动发布时间
        /// </summary>
        /// <param name="problemIds"></param>
        /// <param name="startTime"></param>
        public void BatchAutoShowTime(int[] ids, DateTime startTime, Action<fastCSharp.net.returnValue<int>> onReturn)
        {
            if (currentUser.Permission == dataModel.user.permission.Admin) diantou.examDataAccess.tcpCall.examProblem.reworkAutoShowTime(ids, startTime, onReturn);
            else onReturn(0);
        }
    }
}
